/**
 * Created by joy on 03/09/2017.
 */
import CommonUtil from './common/utils/CommonUtil'
import deploySmartContract from './tools/eth/deploySmartContract'
import sendEther from './tools/eth/sendEther'
import decryptKeystoreToPrivateKey from './tools/eth/decryptKeystoreToPrivateKey'
import decodeTransaction from './tools/eth/decodeTransaction'
import callContract from './tools/eth/callContract'
import queryContract from './tools/eth/queryContract'
import getContractMethodId from './tools/eth/getContractMethodId'
import buildCallContractTxHex from './tools/eth/buildCallContractTxHex'
import buildSendTxHex from './tools/eth/buildSendTxHex'
import buildDeploySmartContractTxHex from './tools/eth/buildDeploySmartContractTxHex'
import searchEventLogs from './tools/eth/searchEventLogs'
import listenEvent from './tools/eth/listenEvent'
import getInfoOfAddress from './tools/bcc/getInfoOfAddress'
import broadcast from './tools/bcc/broadcast'
import disperseUtxo from './tools/bcc/disperseUtxo'
import geneAddresses from './tools/bcc/geneAddresses'
import geneParentKeys from './tools/bcc/geneParentKeys'
import importAddress from './tools/bcc/importAddress'
import rebroadcast from './tools/bcc/rebroadcast'
import signTx from './tools/bcc/signTx'
import swipe from './tools/bcc/swipe'

const currency = CommonUtil.getArgv(1);
const method = CommonUtil.getArgv(2);
global['logger'] = console;

(async () => {
  switch (currency) {
    case 'eth':
      switch (method) {
        case 'deploySmartContract':
          await deploySmartContract()
          break
        case 'send':
          await sendEther()
          break
        case 'decryptKeystoreToPrivateKey':
          await decryptKeystoreToPrivateKey()
          break
        case 'decodeTransaction':
          await decodeTransaction()
          break
        case 'queryContract':
          await queryContract()
          break
        case 'callContract':
          await callContract()
          break
        case 'getContractMethodId':
          await getContractMethodId()
          break
        case 'buildCallContractTxHex':
          await buildCallContractTxHex()
          break
        case 'buildSendTxHex':
          await buildSendTxHex()
          break
        case 'buildDeploySmartContractTxHex':
          await buildDeploySmartContractTxHex()
          break
        case 'searchEventLogs':
          await searchEventLogs()
          break
        case 'listenEvent':
          await listenEvent()
          break
        default:
          console.error('method not exist')
      }
      break
    case 'bcc':
      switch (method) {
        case 'getInfoOfAddress':
          await getInfoOfAddress()
          break
        case 'broadcast':
          await broadcast()
          break
        case 'disperseUtxo':
          await disperseUtxo()
          break
        case 'geneAddresses':
          await geneAddresses()
          break
        case 'geneParentKeys':
          await geneParentKeys()
          break
        case 'importAddress':
          await importAddress()
          break
        case 'rebroadcast':
          await rebroadcast()
          break
        case 'signTx':
          await signTx()
          break
        case 'swipe':
          await swipe()
          break
        default:
          console.error('method not exist')
      }
      break
    default:
      console.log('currency not supported')
  }
})().catch((err) => {
  console.error(err)
})

